using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class PrallaxLayer
{
    [SerializeField] private Transform backGround;
    [SerializeField] private float parallaxMultiplier;
    private float backImageLeftEdge;
    private float backImageRightEdge;
    private float backImageFullLength;
    private float backImageHalfLength;
    public void CalculateImageWidth()
    {
        backImageFullLength = backGround.GetComponent<SpriteRenderer>().bounds.size.x;
        backImageHalfLength = backImageFullLength / 2;
    }
    public void Move(float distance)
    {
        backGround.position += Vector3.right * (distance * parallaxMultiplier);
        
    }
    public void LoopBackGround(float cameraLeftEdge, float cameraRightEdge)
    {
        backImageLeftEdge = backGround.position.x - backImageHalfLength;
        backImageRightEdge = backGround.position.x + backImageHalfLength;
        if (cameraLeftEdge > backImageRightEdge)
        {
            backGround.position += Vector3.right * backImageFullLength;
        }
        else if (cameraRightEdge < backImageLeftEdge)
        {
            backGround.position += Vector3.left * backImageFullLength;
        }
    }
}
